namespace :pg do
  desc "Generate 1000 tests"
  task(:tests => :environment) do
    projects=Project.all
    names = projects.map(&:name)
    owners = projects.map(&:owner)
    per_points = projects.map(&:per_point)
    groups = projects.map(&:group_name)
    centers = projects.map(&:costcenter)
    
    names_length = names.length
    owners_length=owners.length
    per_points_length=per_points.length
    groups_length=groups.length
    centers_length=centers.length
    
    1.upto(1000) do |i|
    #   data ={}
    #   data[:name] = names[rand(names_length)]
    #   data[:owner] = owners[rand(owners_length)]
    #   data[:per_point] = per_points[rand(per_points_length)]
    #   data[:group_name] = groups[rand(groups_length)]
    #   data[:costcenter] = centers[rand(centers_length)]

      # Project.create!(data)
       Project.create!(:name => names[rand(names.length)],
                       :owner =>owners[rand(owners_length)],
                       :per_point =>per_points[rand(per_points_length)],
                       :group_name => groups[rand(groups_length)],
                       :costcenter => centers[rand(centers_length)] )
       
       puts "----------#{i}--------  Done !!! ------------------"
     end
  end
end